//
//  SettingViewController.m
//  OurRelaxDemo
//
//  Created by 王雅蓉 on 15/7/1.
//  Copyright (c) 2015年 于宾尧. All rights reserved.
//

#import "SettingViewController.h"

#import "FeedbackViewController.h"
#import "IntroductionViewController.h"
#import <SDImageCache.h>
#import "MusicDetailViewController.h"

@interface SettingViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, assign)CGFloat cache;
@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(backAction)];
    [self.navigationItem.leftBarButtonItem release];
    
    self.tableview1 = [[UITableView alloc]initWithFrame:[[UIScreen mainScreen]bounds] style:UITableViewStylePlain];
    
    self.tableview1.delegate = self;
    self.tableview1.dataSource = self;
    
    [self.view addSubview:self.tableview1];
    
    self.array1  = @[@"清除缓存",@"意见反馈", @"软件简介"];

}
- (void)backAction
{
    
    [self.navigationController popToRootViewControllerAnimated:YES];

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _array1.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuse = @"reuse";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuse];
    }
    if (indexPath.row == 0) {
        
        
        NSString *cacheStr = [NSString stringWithFormat:@"%.2f M", self.cache];
        NSString *str = @"清除缓存  ";
        NSString *str2 = [str stringByAppendingString:cacheStr];
        cell.textLabel.text = str2;
        
    }
    else
    {
    cell.textLabel.text = [self.array1 objectAtIndex:indexPath.row];
    }
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        NSLog(@"aa");
        SDImageCache *cache = [SDImageCache sharedImageCache];
        [cache clearDisk];
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        cell.textLabel.text = @"清除缓存  0.00M";
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"清除成功" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
        [alert show];
        [self performSelector:@selector(dissMissAlert:) withObject:alert afterDelay:0.5];
        [alert release];
        
    }
    if (indexPath.row == 1) {
        
        FeedbackViewController *fir = [[FeedbackViewController alloc]init];
        [self.navigationController pushViewController:fir animated:YES];
        //[self.myDelegate pushToNext:fir];
        
    }
    if (indexPath.row == 2) {
        //        NSLog(@"dd");
        IntroductionViewController *thr = [[IntroductionViewController alloc]init];
        
        [self.navigationController pushViewController:thr animated:YES];
        //[self.myDelegate pushToNext:thr];
        
    }
}
#pragma mark 提示框自动消失
- (void)dissMissAlert:(UIAlertView *)alert
{
    if (alert.visible) {
        [alert dismissWithClickedButtonIndex:0 animated:YES];
    }
}
#pragma mark 计算缓存数量
- (void)viewWillAppear:(BOOL)animated
{
    SDImageCache *cache = [SDImageCache sharedImageCache];
    self.cache = [cache checkTmpSize];
    NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0];
    UITableViewCell *cell = [self.tableview1 cellForRowAtIndexPath:indexPath];
   
    NSString *cacheStr = [NSString stringWithFormat:@"%.2f M", self.cache];
     NSLog(@"{{{{{{{{{{{{{{{%@", cacheStr);
    NSString *str = @"清除缓存";
    NSString *str2 = [str stringByAppendingString:cacheStr];
    cell.textLabel.text = str2;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
